package impl

import (
	"awesomeProject/configs/pool"
	"github.com/gomodule/redigo/redis"
	"log"
)

type RedisStore struct{}

func (RedisStore) Get(key interface{}) (interface{}, error) {
	c := pool.GetRedisConn()
	defer c.Close()
	value, err := redis.String(c.Do("get", key.(string)))
	if err != nil {
		log.Fatal("redis get a value error,", err)
		return value, err
	}
	return value, nil
}

func (RedisStore) Set(key interface{}, value interface{}) error {
	c := pool.GetRedisConn()
	defer c.Close()
	_, err := c.Do("set", key, value)
	if err != nil {
		log.Println("redis set a value error,", err)
		return err
	}
	return nil
}

func (RedisStore) Delete(key interface{}) error {
	c := pool.GetRedisConn()
	defer c.Close()
	_, err := c.Do("del", key)
	if err != nil {
		log.Fatal("del a key error, ", err)
		return err
	}
	return nil
}
